<script type="text/javascript" language="javascript">// <![CDATA[
function checkAll(checktoggle)
{
  var checkboxes = new Array(); 
  checkboxes = document.getElementsByTagName('input');
	for (var i=0; i<checkboxes.length; i++)  
		{
			if (checkboxes[i].type == 'checkbox')   
				{
					checkboxes[i].checked = checktoggle;
				}
		}
			
}

// ]]></script>

<h2>Tasks List of <?= $projects['name']?> </h2>
<hr />
<?php 
foreach ($query as $row)
	{ 
							
								
								//$id[$i] = $row['id'];
								//echo("ID :".$id[$i]."<br/>");
								
								//$i++;
	}	

?>

<?php if($this->session->flashdata('msg')) {?>
<div id="alert" class="alert alert-success">
<i class="icon-ok-circle"></i>  <?= $this->session->flashdata('msg') ?>
</div>
<?php }?>
<div class="row-fluid">
<div class="pull-right"><a href="#default_group" role="button" data-toggle="modal">Create New Task Group</a></div>
</div>

<?php foreach($taskgroups as $taskgroup) {?>
<?php $tasks = $this->task_model->get_tasks_by_taskgroup_and_project($taskgroup->id,$projects['id']);
if((count($tasks))>0){
?>
<!-- Calculate the % completed -->
<header><i class="icon-folder-open"></i> <?= $taskgroup->name?></header>
<form action="<?php echo site_url('user/billing/display_invoice');?>" method="post">
<table width="100%" class="table table-condensed">
<thead>
<tr>
<th></th>
<th>Name</th>
<?php if(!$this->ion_auth->is_client()){?>
<?php }?>
<th>Time Spent</th>
<th>Billed Time</th>
<th>Un-Billed Time</th>

<th>Assigned to</th>
<th>Start date</th>
<th>Due Date</th>
<th>%</th>
<th>Milestone</th>
</tr>
</thead>
<?php foreach($tasks as $task) {
	if(!$task->is_completed){
	$i=0;?>
<tr <?php if($task->completed_percentage == 100){ ?>
class="success"
<?php } elseif($task->completed_percentage == 0) {?>
class="warning"
<?php }?>>
<td><input type="checkbox" name="box[]" value="<?php echo $task->id;?>"></td>
<td><a href="<?=site_url('user/tasks/task_detail').'/'.$task->id?>"><?=$task->title?></a></td>
<?php if(!$this->ion_auth->is_client()){?>
<td><?=$task->time_spent?></td>
<td>
<?php echo ($query4[$i]);?>
</td>
<td >
<?php echo ($query3[$i]);?>
</td>
<?php $i++;?>
<td>
<?php echo $username = $this->common_model->get_username_id($task->user_id);?>	
</td>
<?php }?>
<td><?=$task->start_date?></td>
<td><?=$task->end_date?></td>
<td><?=$task->completed_percentage?> %</td>

<td><?=$task->milestone_id?></td>
<td>
	<?php 
	// get fav
	$fav = $this->task_model->get_fav_tasks($task->id,$this->session->userdata('user_id'));	
	if(count($fav)==0){
	?>
	<a href="javascript:void(0)"  id="fav" onclick="add_fav_project(<?php echo $task->id;?>)"><i class="icon-star-empty" id="star"></i> </a>
	<?php }else{?>	
	<a href="javascript:void(0)"  id="nofav" onclick="remove_fav_project(<?php echo $task->id;?>)" ><i class="icon-star" id="star"></i> </a>
	<?php }?>
	</td>
</tr>
<?php } else {?>
<tr class="error tooltips" title="Closed Tasks">
<td><input type="checkbox" name="box[]" value="<?php echo $task->id;?>"></td>
<td><a href="<?=site_url('user/tasks/task_detail').'/'.$task->id?>"><?=$task->title?></a></td>
<td><?=$task->time_spent?></td>
<td>
<?php echo ($query4[$i]);?>
</td>
<td >
<?php echo ($query3[$i]);?>
</td>
<?php $i++;?>
<td>
<?php if(!$this->ion_auth->is_client()){?>
<td>
<?php echo $username = $this->common_model->get_username_id($task->user_id);?>	
</td>
<?php }?>
<td><?=$task->start_date?></td>
<td><?=$task->end_date?></td>
<td><?=$task->completed_percentage?> %</td>
<td><?=$task->time_spent?></td>
<td><?=$task->milestone_id?></td>
<td>
	<?php 
	// get fav
	$fav = $this->task_model->get_fav_tasks($task->id,$this->session->userdata('user_id'));	
	if(count($fav)==0){
	?>
	<a href="javascript:void(0)"  id="fav" onclick="add_fav_project(<?php echo $task->id;?>)"><i class="icon-star-empty" id="star"></i> </a>
	<?php }else{?>	
	<a href="javascript:void(0)"  id="nofav" onclick="remove_fav_project(<?php echo $task->id;?>)" ><i class="icon-star" id="star"></i> </a>
	<?php }?>
	</td>
</tr>
<?php }} ?>

</table>
<?php }
else
echo("No data!!!");

}?>

<!--Custom task group-->

<?php foreach($custom_taskgroups as $custom_taskgroup) { ?>
<?php 
$custom_tasks = $this->task_model->get_tasks_by_taskgroup_and_project($custom_taskgroup->id,$projects['id']);
if((count($custom_tasks))>0)
{?>
<header><i class="icon-folder-open"></i> <?= $custom_taskgroup->name?></header>

<table width="100%" class="table table-condensed">
<thead>
<tr>
<th></th>
<th>Name</th>
<th>Time Spent</th>
<th>Billed Time</th>
<th>Un-Billed Time</th>
<th>Assigned to</th>
<th>Start Date</th>
<th>Due Date</th>
<th>%</th>
<th>Milestone</th>
</tr>
</thead>
<?php $i=0;?>
<?php foreach($custom_tasks as $custom_task) {?>

<?php if(!$custom_task->is_completed) {?>
<tr 
<?php if($custom_task->completed_percentage == 100){ ?>
class="success"
<?php } elseif($custom_task->completed_percentage == 0) {?>
class="warning"
<?php }?>
>
<td><input type="checkbox" name="box[]" value="<?php echo $custom_task->id;?>"></td>
<td><a href="<?=site_url('user/tasks/task_detail').'/'.$custom_task->id?>"><?=$custom_task->title?></a></td>
<td><?=$custom_task->time_spent?></td>

<td>
<?php echo ($query4[$i]);?>
</td>
<td >
<?php echo ($query3[$i]);?>
</td>
<?php $i++;?>


<td><?php
echo $username = $this->common_model->get_username_id($custom_task->user_id);
//echo $username['username'];
?></td>
<td><?=$custom_task->start_date?></td>
<td><?=$custom_task->end_date?></td>
<td><?=$custom_task->completed_percentage?> %</td>

<td><?=$custom_task->milestone_id?></td>
<td>
	<?php 
	// get fav
	$fav = $this->task_model->get_fav_tasks($custom_task->id,$this->session->userdata('user_id'));	
	if(count($fav)==0){
	?>
	<a href="javascript:void(0)"  id="fav" onclick="add_fav_project(<?php echo $custom_task->id;?>)"><i class="icon-star-empty" id="star"></i> </a>
	<?php }else{?>	
	<a href="javascript:void(0)"  id="nofav" onclick="remove_fav_project(<?php echo $custom_task->id;?>)" ><i class="icon-star" id="star"></i> </a>
	<?php }?>
	</td>

</tr>
<?php } else {?>
<?php $i=0;?>
<tr class="error tooltips" title="Closed Tasks">
<td><input type="checkbox" name="box[]" value="<?php echo $custom_task->id;?>"></td>
<td><a href="<?=site_url('user/tasks/task_detail').'/'.$custom_task->id?>"><?=$custom_task->title?></a></td>
<td><?=$custom_task->time_spent?></td>
<td>
<?php echo ($query4[$i]);?>
</td>
<td >
<?php echo ($query3[$i]);?>
</td>
<?php $i++;?>
<td><?php
echo $username = $this->common_model->get_username_id($custom_task->user_id);
//echo $username['username'];
?></td>
<td><?=$custom_task->start_date?></td>
<td><?=$custom_task->end_date?></td>
<td>

<?=$custom_task->completed_percentage?> %

</td>

<td><?=$custom_task->milestone_id?></td>
<td>
	<?php 
	// get fav
	$fav = $this->task_model->get_fav_tasks($custom_task->id,$this->session->userdata('user_id'));	
	if(count($fav)==0){
	?>
	<a href="javascript:void(0)"  id="fav" onclick="add_fav_project(<?php echo $custom_task->id;?>)"><i class="icon-star-empty" id="star"></i> </a>
	<?php }else{?>	
	<a href="javascript:void(0)"  id="nofav" onclick="remove_fav_project(<?php echo $custom_task->id;?>)" ><i class="icon-star" id="star"></i> </a>
	<?php }?>
	</td>
</tr>
<?php }}?>
</table>
<?php } 
else
echo("No data!!!");
}?>
<img class="selectallarrow" width="38" height="22" src="<?=base_url()?>assets/img/arrow_ltr.png" alt="With selected:" />
<a onclick="javascript:checkAll(true);" href="javascript:void();">Check All</a>

 / 

<a onclick="javascript:checkAll(false);" href="javascript:void();">Uncheck All</a>
		
<input type="hidden" name="project_id" value="<?php echo $query2;?>">		

</br>
<input class="previous paginate_button" type="submit" name="submit">
</form>

<!-- Add default groups-->
<div id="default_group" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
 <?= form_open('user/tasks/tasks/custom_taskgroup/'.$projects['id'])?>
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
    <h3 id="myModalLabel">Add custom task group</h3>
  </div>
  <div class="modal-body">
    <p>   
    <textarea placeholder="Add custom task group" class="span12" name="subtask"></textarea>    
    </p>
  
  </div>
  <div class="modal-footer">
    <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
    <button class="btn btn-info" type="submit">Save changes</button>
    </form>
  </div>
</div>

<script type="text/javascript">
<!--
	function add_fav_project(pId) {		
		$.post('<?= site_url("user/tasks/add_fav_tasks");?>',{id:pId}, function(data) {						
			//$('#fav').hide();
		//	$('#nofav').show();
			location.reload();
	});
	}
	function remove_fav_project(pId) {	
		$.post('<?= site_url("user/tasks/remove_fav_tasks");?>',{id:pId}, function(data) {			
			//$('#fav').show();
			//$('#nofav').hide();
			location.reload();
	});
	}
	//})
//-->
</script>
